﻿using System;
using System.Runtime.Serialization;
using CC.Yacht.Interfaces;

namespace CC.Yacht.Server
{
    public class ExtendedUser : IComparable<User>, IEquatable<User>, IComparable<ExtendedUser>, IEquatable<ExtendedUser>
    {
        #region Constructor
        public ExtendedUser() : this(-1, false, DateTime.MinValue)
        {
            // Empty Constructor    
        }

        public ExtendedUser(long userId, bool isDeleted, DateTime created)
        {
            Created = created;
            IsDeleted = isDeleted;
            UserId = userId;
        }

        public ExtendedUser(string email, string username, string password, bool isPasswordEncrypted)
        {
            Email = email;
            IsPasswordEncrypted = isPasswordEncrypted;
            Password = password;
            Username = username;
        }
        #endregion

        #region Public Properties
        public IYachtServiceCallback Callback { get; set; }

        public DateTime Created { get; private set; }

        public string Email { get; set; }

        public bool IsDeleted { get; private set; }

        public bool IsPasswordEncrypted { get; set; }

        public bool IsValid
        {
            get
            {
                //NOTE: Should be validating the email address also.
                return (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(Username));
            }
        }

        public string Password { get; set;}

        public long UserId { get; set; }

        public string Username { get; set; }
        #endregion

        #region Public Methods
        /*
        public static bool operator ==(ExtendedUser user1, ExtendedUser user2)
        {
            return user1.Equals(user2);
        }

        public static bool operator !=(ExtendedUser user1, ExtendedUser user2)
        {
            return !user1.Equals(user2);
        }

        public static bool operator ==(ExtendedUser user1, User user2)
        {
            return user1.Equals(user2);
        }

        public static bool operator !=(ExtendedUser user1, User user2)
        {
            return !user1.Equals(user2);
        }
        */

        public int CompareTo(ExtendedUser other)
        {
            int returnValue = -1;

            if (null != other)
            {
                returnValue = UserId.CompareTo(other.UserId);
            }

            return returnValue;
        }

        public int CompareTo(User other)
        {
            int returnValue = -1;

            if (other != null)
            {
                returnValue = UserId.CompareTo(other.UserId);
            }

            return returnValue;
        }

        public bool Equals(ExtendedUser other)
        {
            bool returnValue = false;

            if (null != other)
            {
                returnValue = (UserId == other.UserId);
            }

            return returnValue;
        }

        public bool Equals(User other)
        {
            bool returnValue = false;

            if (other != null)
            {
                returnValue = (UserId == other.UserId);
            }

            return returnValue;
        }

        public User ToUser()
        {
            return new User(UserId, Username);
        }
        #endregion
    }
}
